package cn.service.impl;

import cn.service.AttributeValueService;
import entity.Result;
import mapper.AttributeValueMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AttributeValueServiceImpl implements AttributeValueService {
    @Resource
    AttributeValueMapper attributeValueMapper;

    @Override
    public Result queryAttributeValueNum(Integer attribute_id) {
        if (attributeValueMapper.queryAttributeValueNum(attribute_id) > 1) {//是否可选:多选(1)
            return Result.success(1);
        } else {
            return Result.success(0);
        }
    }

    /**
     * 根据某个attribute_id查询所有value,返回多个字符串对象的集合
     * @param attribute_id
     * @return Result
     */
    @Override
    public Result queryByAttribute_id(Integer attribute_id) {
        List<String> list = attributeValueMapper.queryByAttribute_id(attribute_id);
        String str = "";
        for (int i = 0; i < list.size(); i++) {
            str += list.get(i);
            if (i < list.size() - 1) {
                str += ",";
            }
        }
        return Result.success(str);
    }
}
